﻿using System;
using System.IO;
using System.Web;
using System.Web.Mvc;

namespace Class.Web.Mvc.Extensions
{
    public static class HttpServerUtilityBaseExtension
    {

        #region Area

        public static string AreaContentPath(this HttpServerUtilityBase helper, string area)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Areas/" + area + "/Content/"));
        }

        public static string AreaScriptPath(this HttpServerUtilityBase helper, string area)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Areas/" + area + "/Content/js/"));
        }

        public static string AreaCssPath(this HttpServerUtilityBase helper, string area)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Areas/" + area + "/Content/css/"));
        }

        public static string AreaImagesPath(this HttpServerUtilityBase helper, string area)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Areas/" + area + "/Content/images/"));
        }

        public static string AreaScriptPath(this HttpServerUtilityBase helper, string area, string module)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Areas/" + area + "/Content/js/" + module + "/"));
        }

        public static string AreaCssPath(this HttpServerUtilityBase helper, string area, string module)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Areas/" + area + "/Content/css/" + module + "/"));
        }

        public static string AreaImagesPath(this HttpServerUtilityBase helper, string area, string module)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Areas/" + area + "/Content/images/" + module + "/"));
        }

        public static string AreaContentVitualPath(this HttpServerUtilityBase helper, string area)
        {
            return "/Areas/" + area + "/Content/";
        }

        public static string AreaScriptVitualPath(this HttpServerUtilityBase helper, string area)
        {
            return "/Areas/" + area + "/Content/js/";
        }

        public static string AreaCssVitualPath(this HttpServerUtilityBase helper, string area)
        {
            return "/Areas/" + area + "/Content/css/";
        }

        public static string AreaImagesVitualPath(this HttpServerUtilityBase helper, string area)
        {
            return "/Areas/" + area + "/Content/images/";
        }

        public static string AreaScriptVitualPath(this HttpServerUtilityBase helper, string area, string module)
        {
            return "/Areas/" + area + "/Content/js/" + module + "/";
        }

        public static string AreaCssVitualPath(this HttpServerUtilityBase helper, string area, string module)
        {
            return "/Areas/" + area + "/Content/css/" + module + "/";
        }

        public static string AreaImagesVitualPath(this HttpServerUtilityBase helper, string area, string module)
        {
            return "/Areas/" + area + "/Content/images/" + module + "/";
        }

        #endregion

        #region Default

        public static string AreaContentPath(this HttpServerUtilityBase helper)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Content/"));
        }

        public static string AreaScriptDefaultPath(this HttpServerUtilityBase helper)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/Scripts/"));
        }

        public static string AreaScriptPath(this HttpServerUtilityBase helper)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/js/"));
        }

        public static string AreaCssPath(this HttpServerUtilityBase helper)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/css/"));
        }

        public static string AreaImagesPath(this HttpServerUtilityBase helper)
        {
            return helper.MapPath(VirtualPathUtility.ToAbsolute("/images/"));
        }

        public static bool Delete(this HttpServerUtilityBase helper, string folder, string fileName)
        {
            string name = helper.MapPath(string.Format("/Upload/{0}/", folder)) + fileName;
            if (File.Exists(name))
            {
                try
                {
                    File.Delete(name);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
            return false;
        }

        #endregion

        #region Upload Folder

        public static string UploadPath(this HttpServerUtilityBase helper)
        {
            return helper.MapPath("/Upload/UserUpload/");
        }

        public static string UploadPath(this HttpServerUtilityBase helper, string controllerName)
        {
            return helper.MapPath(string.Format("/Upload/{0}/", controllerName));
        }

        public static string UploadVitualPath(this HtmlHelper helper)
        {
            return "/Upload/UserUpload/";
        }

        public static string UploadVitualPath(this HtmlHelper helper, string controllerName)
        {
            return string.Format("/Upload/{0}/", controllerName);
        }

        public static void Save(this System.Drawing.Image helper, string folder, string fileName)
        {
            helper.Save(folder + fileName);
        }

        #endregion

        #region ActionLink

        public static string ActionLink(this HttpServerUtilityBase helper, string text, string url)
        {
            return string.Format("<a href=\"{0}\">{1}</a>", url, text);
        }

        public static string ActionLink(this HttpServerUtilityBase helper, string text, string url, string style)
        {
            return string.Format("<a href=\"{0}\" style=\"{2}\" >{1}</a>", url, text, style);
        }

        public static string ActionLink(this HttpServerUtilityBase helper, string text, string url, string @class, string style)
        {
            return string.Format("<a href=\"{0}\" class=\"{2}\" style=\"{3}\" >{1}</a>", url, text, @class, style);
        }

        #endregion

    }
}
